#include <iostream>
#include <assert.h>
#include <vector>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <task.hpp>
using namespace std;

#define PROCESS_NUM 5

int waitCommand(int waitfd)
{
    uint32_t command = 0;
    ssize_t s = read(waitfd, &command, sizeof(command));
    assert(s == sizeof(uint32_t));
    //执行
    return command;
}
int main()
{
    vector<pair<pid_t, int>> slot; // pid pipefd键值对

    for (int i = 0; i < PROCESS_NUM; i++)
    {
        int pipefd[2] = {0};
        int n = pipe(pipefd);
        assert(n > 0);
        (void)n;

        pid_t id = fork();
        assert(id != -1);
        //子进程做读
        if (!id)
        {
            close(pipefd[1]);
            //子进程
            while (1)
            {
                int n = waitCommand(pipefd[0]); //没信号，就阻塞
                //执行对应的命令
            }
            exit(1);
        }
        //父进程
        close(pipefd[0]);
        slot.push_back(pair<pid_t, int>(id, pipefd[1]));
    }

    //关闭fd和所有进程

    return 0;
}